#ifndef		__ENGINE_SCOPEGUARD_H_INCLUDED__
#define		__ENGINE_SCOPEGUARD_H_INCLUDED__

#include	<functional>

/**
 * Simple scope guard.
 */
class ScopeGuard {
public:
	ScopeGuard(const std::function<void()> & f) : _f(f), _dismissed(false) {}
	~ScopeGuard() { if (!_dismissed && _f) _f(); }

	/**
	 * Dismiss callback when destruct self.
	 */
	inline void Dismiss() { _dismissed = true; }

private:
	std::function<void()> _f;
	bool _dismissed;
};

#endif//!	__ENGINE_SCOPEGUARD_H_INCLUDED__
